<?php
  include("../conn.php");
  $title = $_GET['title'];
  $text = $_GET['text'];
  $time = $_GET['time'];
  $owner = $_GET['owner'];
  // $imageNumber = $_GET['imageNumber'];
  $image = $_GET['image'];
  $imageNumber = sizeof($image);

  
  $sql = "INSERT INTO `issue_list` (`title`, `text`, `time`, `owner`, `imageNumber`) VALUES ('{$title}', '{$text}', '{$time}', '{$owner}', '{$imageNumber}');";
  $query = mysql_query($sql);
  $sql = "SELECT * FROM `issue_list` where `owner` = '$owner' order by time desc limit 1";
  $query = mysql_query($sql);
  while ($rs = mysql_fetch_array($query)) $issue = array(
    'id' => $rs['id'],
    'title' => $rs['title'],
    'text' => $rs['text'],
    'imageNumber' => $rs['imageNumber'],
    'likes' => $rs['likes'],
    'comments' => $rs['comments'],
    'visits' => $rs['visits'],
    'validity' => $rs['validity'],
    'time' => $rs['time'],
    'thumb' => $rs['thumb'],
  );
  $id = $issue['id'];
  for ($i = 0; $i < $imageNumber; $i++) {
    $sql = "INSERT INTO `issue_image` (`issue`, `time`, `image`) VALUES ('{$id}', '{$time}', '{$image[$i]}');";
    $query = mysql_query($sql);
  }
  print_r(json_encode($issue));
  mysql_close($link);

?>